// JavaScript Document
function TabControl(containerId,instancename){
	if(!containerId) return;
	var tabContainer=$(containerId);
	var curTabIndex=0;
	var tabText=getAttr(tabContainer,"tabText");
	var tabPrefix=getAttr(tabContainer,"tabPrefix");
	var tabDefultIndex=getAttr(tabContainer,"tabDefultIndex");
	var tabAry=tabText.split("|");
	var instanceName=instancename;
	if(tabDefultIndex)curTabIndex=tabDefultIndex;
	function getAttr(obj,attr){
		if(!obj) return;
		if(!attr) return;
		return obj.getAttribute(attr);
	}
	function setAttr(){
	}
	function setStyle(obj,csstxt){
		if(!+"\v1"){
			obj.style.setAttribute('cssText',csstxt);
		}else{
			obj.setAttribute('style',csstxt);
		}
	}
	function $(elem){
		return document.getElementById(elem);
	}
	function $class(){
	}
	function showTabContent(){
		var index=(curTabIndex>9)?curTabIndex:"0"+curTabIndex;
		var tbc=$(tabPrefix+index);
		var len=tabAry.length;
		tbc.style.display='';
		for(var i=0;i<len;i++){
			if(curTabIndex!=i){
				index=(i>9)?i:"0"+i;
				tbc=$(tabPrefix+index);
				tbc.style.display='none';
			}
		}
	}
	function creatediv(css,id,txt){
		var div=document.createElement("div");
		if(css){
			setStyle(div,css);
		}
		if(id){
			div.id=id;
		}
		if(txt){
			div.innerHTML=txt;
		}
		return div;
	}
	function tabActive(txt,index){
		var idx=(index>9)?index:"0"+index;
		var divs=creatediv("float:left; height:23px;","__TabPage_"+idx);
		divs.appendChild(creatediv("float:left;background:url(../images/tab_active1_left_cui.gif) bottom; height:23px; width:11px;"));
		divs.appendChild(creatediv("float:left;background:url(../images/tab_active_background_cui.gif)  bottom repeat-x; height:23px;color: #990000;font-weight: bold;line-height:23px;","",txt));
		divs.appendChild(creatediv("float:left;background:url(../images/tab_active_right_cui.gif) bottom; height:23px; width:23px;"));
		return divs;
	}
	function tabInactive(txt,index){
		var idx=(index>9)?index:"0"+index;
		var divs=creatediv("float:left; height:23px;","__TabPage_"+idx);
		divs.appendChild(creatediv("float:left;background:url(../images/tab_inactive2_left_cui.gif) bottom; height:23px; width:11px;"));
		divs.appendChild(creatediv("float:left;background:url(../images/tab_inactive_background_cui.gif)  bottom repeat-x; height:23px;line-height:20px;","","<a href='#' class='tabinactive' onclick='"+instanceName+".chageTab("+index+");return false'>"+txt+"</a>"));
		divs.appendChild(creatediv("float:left;background:url(../images/tab_inactive_right_cui.gif) bottom; height:23px; width:23px;"));
		return divs;
	}
	
	function tabRightBorder(){
		return creatediv("float:right;width:6px; height:23px; background:url(../images/tab_right_corner_cui.gif) right bottom no-repeat");
	}
	this.makeTabControl=function(){
		//var oFrag   = document.createDocumentFragment();
		var len=tabAry.length;
		var tabs=document.createElement("div");
		setStyle(tabs,"background:url(../images/tab_background_cui.gif) bottom repeat-x;height:23px;width:100%; margin:0; padding:0");
		tabs.id="__TabControl";
		for(var i=0;i<len;i++){
			(function(idx){
				if(curTabIndex==idx){
					tabs.appendChild(tabActive(tabAry[idx],idx));
				}else{
					tabs.appendChild(tabInactive(tabAry[idx],idx));
				}
			})(i)
		}
		//oFrag.appendChild(tabs);
		tabs.appendChild(tabRightBorder())
		if($("__TabControl"))tabContainer.removeChild($("__TabControl"))
		tabContainer.appendChild(tabs);
		showTabContent();
	}
	this.chageTab=function(index){
		curTabIndex=index;
		this.makeTabControl();
	}
};